﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

using PdfSharp.Viewing;

namespace NN
{
    public class PDFViewer : Form
    {
        private PdfSharp.Viewing.PdfAcroViewer theViewer;
        private bool fileLoaded;
        private Button button1;

        public System.Resources.ResourceManager resources;
        
        public string Title { get; set; }

        public PDFViewer()
        {
            resources = new System.Resources.ResourceManager(typeof(PDFViewer));            
            this.button1 = new Button();
            this.button1.Location = new System.Drawing.Point(4, 4);
            this.button1.Name = "button1";
            this.button1.TabIndex = 1;
            this.button1.Text = "Close";
            this.button1.Click += new System.EventHandler(this.button1_Click);            

            fileLoaded = false;
            this.Text = Title;
            this.Size = new System.Drawing.Size(692, 666);
            this.Hide();

            theViewer = new PdfSharp.Viewing.PdfAcroViewer();
            theViewer.Location = new System.Drawing.Point(0, 34);
            theViewer.Name = "acroViewer";
            theViewer.Size = new System.Drawing.Size(680, 632);

            this.Controls.Add(button1);
            this.Controls.Add(theViewer);
            this.ControlBox = false;
            //this.FormClosing += new FormClosingEventHandler(PDFViewer_FormClosing);
        }

        void button1_Click(object sender, EventArgs e)
        {
            this.Close();            
        }

        public void SetTitle()
        {
            this.Text = this.Title;
        }

        public bool LoadPDF(string fileName)
        {
            fileLoaded = theViewer.LoadFile(fileName);

            if (fileLoaded)
            {
                theViewer.Show();
                //this.Hide();
                theViewer.SetPageMode(PdfSharp.Pdf.PdfPageMode.FullScreen);
                this.Show();
            }
            else
            {
                MessageBox.Show("There was an error opening the file, please make sure it exists on the disk.");
                this.Hide();
                //this.Dispose();
                //theViewer.Dispose();
            }

            return fileLoaded;
        }

    }
}